//
//  NetworkMusicViewController.m
//  播放音乐(AVPlayer)
//
//  Created by 刘家俊 on 17/4/7.
//  Copyright © 2017年 Andrew. All rights reserved.
//

#import "NetworkMusicViewController.h"
#import <AVFoundation/AVFoundation.h>

@interface NetworkMusicViewController ()

/* 播放器 */
@property (nonatomic, strong) AVPlayer *player;


@end

@implementation NetworkMusicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
}

- (AVPlayer *)player
{
    if (!_player) {
        //1.创建音乐资源
//        NSURL *url = [NSURL URLWithString:@"http://cc.stream.qqmusic.qq.com/C100003j8IiV1X8Oaw.m4a?fromtag=52"];
        NSURL *url = [NSURL URLWithString:@"http://wvoice.spriteapp.cn/voice/2015/0824/55dafc15020d9.mp3"];
        
        AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:url];
        
        //2.创建播放器
        _player = [AVPlayer playerWithPlayerItem:playerItem];
    }
    return _player;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.player play];
}



@end
